package com.zy.config;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.net.URL;
import java.util.Objects;

/**
 * @author LittleDesire
 * @description
 * @date 2022-03-29 周二 16:36
 * @since 17
 */
public class MyCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        try {
            Class<?> animal = Objects.requireNonNull(context.getClassLoader()).loadClass("com.zy.bean.Animal");
            if (animal != null) {
                return true;
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return false;
    }
}
